package cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemwlmq;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemwlmq.vo.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemWlmqDO;
import cn.iocoder.yudao.module.erp.service.giitem.GiItemWlmqService;

@Tag(name = "管理后台 - ERP物流乌鲁木齐仓库货号详情")
@RestController
@RequestMapping("/erp/gi-item-wlmq")
@Validated
public class GiItemWlmqController {

    @Resource
    private GiItemWlmqService giItemWlmqService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流乌鲁木齐仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:create')")
    public CommonResult<String> createGiItemWlmq(@Valid @RequestBody GiItemWlmqSaveReqVO createReqVO) {
        return success(giItemWlmqService.createGiItemWlmq(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流乌鲁木齐仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:update')")
    public CommonResult<Boolean> updateGiItemWlmq(@Valid @RequestBody GiItemWlmqSaveReqVO updateReqVO) {
        giItemWlmqService.updateGiItemWlmq(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流乌鲁木齐仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:delete')")
    public CommonResult<Boolean> deleteGiItemWlmq(@RequestParam("id") Long id) {
        giItemWlmqService.deleteGiItemWlmq(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流乌鲁木齐仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:query')")
    public CommonResult<GiItemWlmqRespVO> getGiItemWlmq(@RequestParam("id") Long id) {
        GiItemWlmqDO giItemWlmq = giItemWlmqService.getGiItemWlmq(id);
        return success(BeanUtils.toBean(giItemWlmq, GiItemWlmqRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流乌鲁木齐仓库货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:query')")
    public CommonResult<PageResult<GiItemWlmqRespVO>> getGiItemWlmqPage(@Valid GiItemWlmqPageReqVO pageReqVO) {
        PageResult<GiItemWlmqDO> pageResult = giItemWlmqService.getGiItemWlmqPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiItemWlmqRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流乌鲁木齐仓库货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-wlmq:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiItemWlmqExcel(@Valid GiItemWlmqPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiItemWlmqDO> list = giItemWlmqService.getGiItemWlmqPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流乌鲁木齐仓库货号详情.xls", "数据", GiItemWlmqRespVO.class,
                        BeanUtils.toBean(list, GiItemWlmqRespVO.class));
    }

}